package com.example.demo.controller;

import com.example.demo.entity.Product;
import com.example.demo.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
   final static Logger logger = LoggerFactory.getLogger(ProductController.class);
    @Autowired
    private ProductService productService;
    @GetMapping("/select")
    public Product selectProductById(Integer id){
        logger.info("查询开始");
        return productService.selectProductById(id);
    }
    @PostMapping("/insert")
    public Integer insertProduct(@RequestBody Product product){
        return productService.insertProduct(product);
    }
    @DeleteMapping("/deletebyid")
    public Integer deleteProductById(Integer id){
        return productService.deleteProductById(id);
    }
    @PutMapping("/updatebyid")
    public Integer updateProductById(Integer id,Integer number) {
        return productService.updateProductById(id,number);
    }
    @GetMapping("/selectCountWhere")
    public Integer selectCountWhere(Product product){
        return  productService.selectCountWhere(product);
    };
    @GetMapping("/selectDistinctName")
    public List<String> selectDistinctName(){
        return productService.selectDistinctName();
    };
}
